package com.markus.code.exam.baidu;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/3 20:34
 * todo:
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            int n = scanner.nextInt();
            for (int r=0;r<n;r++){
                int num = scanner.nextInt();
                int teXing = scanner.nextInt();
                int []nai = new int[num];
                int count = 0;
                List<Integer> ans = new ArrayList<>();
                for (int row = 0;row<teXing;row++){
                    int k = scanner.nextInt();
                    for (int i=0;i<k;i++){
                        int start = scanner.nextInt();
                        int end = scanner.nextInt();
                        for (int j = start;j<=end;j++){
                            nai[j-1] += 1;
                        }
                    }
                }
                for (int i=0;i<num;i++){
                    if (nai[i] >= teXing){
                        count++;
                        ans.add(i+1);
                    }
                }
                print(count,ans);
            }
        }
    }
    private static void print(int count,List<Integer> ans){
        if (count == 0){
            return;
        }
        System.out.println(count);
        for (Integer an : ans) {
            System.out.print(an+" ");
        }
    }
}
